package us.ajg0702.leaderboards.libs.bungee;

import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.config.Configuration;
import net.md_5.bungee.config.ConfigurationProvider;
import net.md_5.bungee.config.YamlConfiguration;

import java.io.File;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.regex.Matcher;

public class BungeeMessages {
    static BungeeMessages INSTANCE = null;
    Plugin pl;
    ConfigurationProvider cv = ConfigurationProvider.getProvider(YamlConfiguration.class);
    Configuration msgs;
    File msgFile;
    LinkedHashMap<String, String> defaultValues;
    private BungeeMessages(Plugin pl, LinkedHashMap<String, String> defaultValues) {
        this.pl = pl;
        this.defaultValues = defaultValues;
        loadMessagesFile(defaultValues);
    }

    public static BungeeMessages getInstance() {
        return INSTANCE;
    }

    public static BungeeMessages getInstance(Plugin pl, LinkedHashMap<String, String> defaultValues) {
        if (INSTANCE == null) {
            INSTANCE = new BungeeMessages(pl, defaultValues);
        }
        return INSTANCE;
    }

    private void loadMessagesFile(LinkedHashMap<String, String> d) {
        this.msgFile = new File(this.pl.getDataFolder(), "messages.yml");
        if (!this.msgFile.exists()) {
            try {
                this.pl.getDataFolder().mkdirs();
                this.msgFile.createNewFile();
            } catch (IOException e) {
                this.pl.getLogger().severe("Unable to create messages file:");
                e.printStackTrace();
            }
        }
        try {
            this.msgs = this.cv.load(this.msgFile);
        } catch (IOException e) {
            this.pl.getLogger().severe("Unable to load messages file:");
            e.printStackTrace();

            return;
        }
        for (String k : d.keySet()) {

            if (!this.msgs.contains(k)) {
                this.msgs.set(k, d.get(k));
            }
        }
        try {
            this.cv.save(this.msgs, this.msgFile);
        } catch (IOException e) {
            this.pl.getLogger().severe("Unable to save messages file:");
            e.printStackTrace();
        }
    }

    public String get(String key) {
        String msg = this.msgs.get(key, "&cMessage '" + key + "' does not exist!");
        msg = color(msg);
        return msg;
    }

    public BaseComponent[] getBC(String key, String... placeholders) {
        String m = get(key);
        for (String sr : placeholders) {

            String placeholder = sr.split(":")[0];
            String value = sr.replaceFirst(Matcher.quoteReplacement(placeholder + ":"), "");
            m = m.replaceAll("\\{" + Matcher.quoteReplacement(placeholder) + "\\}", value);
        }
        return TextComponent.fromLegacyText(m);
    }

    public String color(String msg) {
        return ChatColor.translateAlternateColorCodes('&', msg).replaceAll(Matcher.quoteReplacement("\\n"), "\n");
    }

    public void reload() {
        loadMessagesFile(this.defaultValues);
    }
}


*Location:D:\User\Xuan\Downloads\ajLeaderboards-1.3.3.jar\\us\ajg0702\leaderboards\libs\bungee\BungeeMessages.class
 *Java compiler version:8(52.0)
         *JD-Core Version:1.1.3
